package mt.dummy;

import java.util.ArrayList;
import java.util.LinkedList;

import mt.Order;
import mt.comm.ClientComm;
import mt.comm.ClientSideMessage;

public class ClientCommHandler implements ClientComm {

	private LinkedList<Order> orders = new LinkedList<Order>();
	private boolean isConnected;
	private String nickname;
	@Override
	public void connect(String serverAddress, String nickname) {
		isConnected = true;
		this.nickname = nickname;
	}

	@Override
	public boolean isConnected() {
		return isConnected;
	}
	
	public String getInstance() {
		return "Testing";
	}

	@Override
	public void disconnect() {
		isConnected = false;
	}

	@Override
	public boolean hasNextMessage() {
		return orders.size() > 0;
	}

	@Override
	public ClientMessage getNextMessage() {
		System.out.println("Get next message");
		return new ClientMessage(ClientSideMessage.Type.ORDER, orders.poll());
	}

	@Override
	public void sendOrder(Order order) {
		orders.add(order);		
	}

}
